#include "MenuItem.h"
#include "../Settings.h"
#include "iostream"

#include <GL/gl.h>
MenuItem::MenuItem() : 
item_font(Settings::instance().getStringValue("menu","font_file"), 0.05f, 0.035f)
{
}
/*
MenuItem::MenuItem(float top, float bot, float left, float right) 
    : top(top), bot(bot),
    left(left), right(right),
    item_font(Settings::instance().getStringValue("menu","font_file"), 0.05f, 0.035f)
{
}
*/
MenuItem::~MenuItem() {
}

void
MenuItem::render(float top, float bot, float left, float right, bool current) {
    float o = 0.01f;
    if (current) {
        left -= o;
        right += o;
        top += o;
        bot -= o;
    }

    glDisable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);

    if (current) {
        glColor4f(0.0f, 0.0f, 0.5f, 0.5f);
    } else {
        glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
    }
    glVertex3f(left, top, 0.0f);
    glVertex3f(left, bot, 0.0f);

    if (current) {
        glColor4f(0.0f, 0.0f, 0.5f, 0.5f);
    } else {
        glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
    }
    glVertex3f(right, bot, 0.0f);
    glVertex3f(right, top, 0.0f);

    glEnd();

    float avg = (top + bot) / 2.0f;
//    std::cerr << name << ": MenuBox( top=" << top
//                               << ", bot=" << bot
//                               << ", left=" << left
//                               << ", right=" << right
//                               << ")\n";
//    std::cerr << avg << std::endl;
    glPushMatrix();
    glColor3f(0.9f, 0.9f, 0.7f);
    glTranslatef(0.35f, avg, 0.0f);
    item_font.renderString(name);
    glPopMatrix();

    if (current) {
        left += o;
        right -= o;
        top -= o;
        bot += o;
    }
}

void MenuItem::activate() {
}

